package com.example.design.ordermanagement.audit;

import java.util.Date;

//模板方法模式抽象模板对象
public abstract class AbstractAuditLogProcessor {

    //定义审计日志的基本信息
    private final OrderAuditLog basicAuditLog(String account,String action,String orderId){
        return OrderAuditLog.builder()
                .account(account)
                .action(action)
                .orderId(orderId)
                .date(new Date())
                .build();
    }

    //定义抽象模板方法，设置订单审计日志的额外信息，供子类实现
    protected abstract OrderAuditLog buildDetails(OrderAuditLog orderAuditLog);

    //定义审计日志的创建步骤
    public final OrderAuditLog createAuditLog(String account,String action,String orderId){
        //设置审计日志的基本信息
        OrderAuditLog orderAuditLog = basicAuditLog(account,action,orderId);
        //设置日志的额外信息
        return buildDetails(orderAuditLog);
    }
}
